﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using QLTV_Public;
using QLTV_BLL;

namespace GUI
{
    public partial class uc_QuaHan : DevExpress.XtraEditors.XtraUserControl
    {
        #region khai bao bien

        CT_PhieuYeuCau_BLL ct_bll = new CT_PhieuYeuCau_BLL();
        bool isGV = true;

        bool isNgayMuon = true;
        bool isNgayTra = false;
        #endregion

        #region LoadForm

        public uc_QuaHan()
        {
            InitializeComponent();
        }

        private void uc_QuaHan_Load(object sender, EventArgs e)
        {
            Load_Data_GiaoVien();
           
        }

        #endregion

        #region cac chuc nang

        private void btnGiaoVien_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            isGV = true;
            Load_Data_GiaoVien();
        }

        private void btnHocVien_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            isGV = false;
            Load_Data_HocVien();
        }

        private void btnTimKiem_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (isGV == true)
                Load_Data_GiaoVien();
            else
                Load_Data_HocVien();
        }

        private void btnIN_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {

        }
        #endregion

        #region Ham viet them

        private void Load_Data_GiaoVien()
        {
            gr_HocVien.Hide();
            gr_GiaoVien.Show();
            gr_GiaoVien.Dock = DockStyle.Fill;
            grd_GiaoVien.DataSource = ct_bll.Load_GiaoVien_QuaHan(txtMaDocGia.Text.Trim(),txtHoTen.Text,txtNhanDe.Text,isNgayMuon,dtpTuNgayMuon.Value,dtpDenNgayMuon.Value,isNgayTra,dtpTuNgayTra.Value,dtpDenNgayTra.Value);
            grv_GiaoVien.BestFitColumns();
        }
        public void Load_Data_HocVien()
        {
            gr_GiaoVien.Hide();
            gr_HocVien.Show();
            gr_HocVien.Dock = DockStyle.Fill;
            grd_HocVien.DataSource = ct_bll.Load_HocVien_QuaHan(txtMaDocGia.Text.Trim(), txtHoTen.Text, txtNhanDe.Text, isNgayMuon, dtpTuNgayMuon.Value, dtpDenNgayMuon.Value, isNgayTra, dtpTuNgayTra.Value, dtpDenNgayTra.Value);
            grv_HocVien.BestFitColumns();
        }
        #endregion

        private void ckbNgayMuon_CheckedChanged(object sender, EventArgs e)
        {
            if (ckbNgayMuon.Checked)
            {
                isNgayMuon = true;
                dtpTuNgayMuon.Enabled = true;
                dtpDenNgayMuon.Enabled = true;
            }
            else
            {
                isNgayMuon = false;
                dtpTuNgayMuon.Enabled = false;
                dtpDenNgayMuon.Enabled = false;
            }
        }

        private void ckbNgayTra_CheckedChanged(object sender, EventArgs e)
        {
            if (ckbNgayTra.Checked)
            {
                isNgayTra = true;
                dtpTuNgayTra.Enabled = true;
                dtpDenNgayTra.Enabled = true;
            }
            else
            {
                isNgayTra = false;
                dtpTuNgayTra.Enabled = false;
                dtpDenNgayTra.Enabled = false;
            }
        }

        private void grv_HocVien_RowStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs e)
        {
            try
            {
                //vẫn đang mượn thì màu vàng
                if ((e.RowHandle != -1) && (grv_HocVien.GetRowCellValue(e.RowHandle, colTrangThaiMuonHV).ToString()=="Đang Mượn"))
                {

                    e.Appearance.BackColor = System.Drawing.Color.Red;

                }
                else if ((e.RowHandle != -1) && grv_HocVien.GetRowCellValue(e.RowHandle, colTrangThaiMuonHV).ToString() == "Đã Trả")
                {

                    e.Appearance.BackColor = System.Drawing.Color.Yellow;

                }
            }
            catch { }
        }

        private void grv_GiaoVien_RowStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs e)
        {
            try
            {
                //vẫn đang mượn thì màu vàng
                if ((e.RowHandle != -1) && (grv_GiaoVien.GetRowCellValue(e.RowHandle, colTrangThaiMuon).ToString() == "Đang Mượn"))
                {

                    e.Appearance.BackColor = System.Drawing.Color.Red;

                }
                else if ((e.RowHandle != -1) && grv_GiaoVien.GetRowCellValue(e.RowHandle, colTrangThaiMuon).ToString() == "Đã Trả")
                {

                    e.Appearance.BackColor = System.Drawing.Color.Yellow;

                }
            }
            catch { }
        }
    }
}
